/**
 * @Title: StudentController.java
 * @Description:
 * @author zsw
 * <p>
 * Copyright(C) 2018-2019    NPlus
 * Company:   无锡核心信息科技有限公司
 * @version V2.0.0
 * @Date: 14:19 2019/10/15
 * <p>
 * 修改历史:
 * Date                 Author        Version        Description
 * -----------------------------------------------------------------------------------
 * 14:19 2019/10/15       zsw        2.0.0           初始化版本
 */
package com.example.springjpa.controller;

import com.example.springjpa.common.ResultVO;
import com.example.springjpa.common.ResultVOUtil;
import com.example.springjpa.model.Student;
import com.example.springjpa.service.StudentService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping( "/test")
    public ResultVO addStudent(Student student) {
            studentService.addStudent(student);
        return ResultVOUtil.success(student);
    }

    @GetMapping("/test")
    public ResultVO getStudents() {

        try {
            Collection<Student> students = studentService.findAll();
            return ResultVOUtil.success(students);
        } catch (Exception e) {
            return ResultVOUtil.error(-1, "查询不到");
        }

    }

    @GetMapping("/test/{id}")
    public ResultVO getStudent(@PathVariable Long id) {
        try {
            Student student = studentService.findOneStudent(id);
            return ResultVOUtil.success(student);
        } catch (Exception e) {
            return ResultVOUtil.error(-1, "查询不到");
        }
    }

    @PutMapping("/test/{id}")
    public ResultVO putStudent(@PathVariable Long id, Student student) {
        student.setId(id);
        student = studentService.putStudent(student);
        return ResultVOUtil.success(student);
    }

    @DeleteMapping("/test/{id}")
    public ResultVO delStudent(@PathVariable Long id) {
        studentService.delStudent(id);
        return ResultVOUtil.success();
    }


}
